package com.zsl.swing.redis.desktop.utils;

import com.zsl.swing.redis.desktop.ZslRedisDesktopMain;
import com.zsl.swing.redis.desktop.window.ZslRedisDesktopMainWindow;

import java.awt.Component;
import java.io.File;
import java.io.IOException;

import javax.swing.JOptionPane;

/**
 * 
 * @author 张帅令
 * @description 对话框工具类
 *
 */
public class DialogUtils {

	private DialogUtils() {}
	
	public static void errorDialog(Component c,String msg) {
		JOptionPane.showMessageDialog(c, msg,"错误",JOptionPane.ERROR_MESSAGE);
	}
	
	public static void errorDialog(String msg) {
		JOptionPane.showMessageDialog(null,msg,"错误",JOptionPane.ERROR_MESSAGE);
	}

	public static void msgDialog(Component c,String object) {
		JOptionPane.showMessageDialog(c, object, "消息", JOptionPane.INFORMATION_MESSAGE);
	}

	public static boolean warnDialog(Component c,String msg) {
		return JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(c, msg,"警告",JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);
	}

    public static boolean confirmDialog(Component c,String msg) {
		return JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(c,msg,"确认",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
    }

	public static void restartConfirmDialog(Component c,String msg) {
		boolean confirm = confirmDialog(c, msg);
		if(confirm){
//			String basePath = System.getProperty("user.dir");
//
//			String filaName = basePath + "RedisDesktop-1.0.0-jar-with-dependencies.jar";
//			File file = new File(filaName);
//			if(!file.exists()){
//				filaName = "E:\\develop\\projects\\Zsl\\RedisDesktop\\target\\RedisDesktop-1.0.0-jar-with-dependencies.jar";
//			}
//
//			final String jarFileName = filaName;
			ZslRedisDesktopMainWindow.closeWindow();

			try{
				Thread.sleep(2000);
				ZslRedisDesktopMainWindow.showWindow();
//				ZslRedisDesktopMain.main(null);
			}catch (Exception e){}
//			new Thread(() ->{
////				try{
////					Thread.sleep(10000);
////				}catch (Exception e){}
//
//				try {
//					Runtime.getRuntime().exec("java -jar " + jarFileName);
//				} catch (IOException e) {
//					e.printStackTrace();
//				}
//			}).start();
//
//			try {
//				Thread.sleep(2000);
//			} catch (InterruptedException e) {
//				e.printStackTrace();
//			}
//
//			System.out.println("user.dir:" + basePath);
		}
	}
}
